package com.woniu.service.impl;

import com.woniu.dao.ClientDao;
import com.woniu.dao.ICapitalChannelDao;
import com.woniu.entity.Client;
import com.woniu.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;


/**
 * 客户列表实现类
 */
@Service
public class ClientServiceImpl implements ClientService {
    @Resource
    @Qualifier("clientDao")
    ClientDao clientDao;

    @Autowired
    ICapitalChannelDao iCapitalChannelDao;


    /**
     * 查询所有客户列表,通过id排序
     * @param client
     * @return
     */
    @Override
    public List<Client> findAll(Client client) {
      Comparator<Client> comparator = new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if(o1 instanceof Client && o2 instanceof Client) {
                    return ((Client) o2).getId() - ((Client) o1).getId();
                }
                return 0;
            }
        };
        Map<String,Client> result = new HashMap<>();
        //查询出所有客户信息
        List<Client> all = clientDao.findAll(client);
        //遍历出客户信息
//        for (Client cls: all) {
//            //根据CitizenIdentity(身份证号)来去重
//            result.put(cls.getCitizenIdentity(),cls);
//        }
//        System.out.println(result.size());
//        List<Client> resultList = new ArrayList<>(result.values());
//
//        Collections.sort(resultList,comparator);
//        System.out.println(resultList.size());
        return all;
      
    }

    /**
     * 通过客户id查询单条客户信息
     * @param id
     * @return
     */
    @Override
    public Client findOne(Integer id) {
        return clientDao.findOne(id);
    }

    /**
     * 导出所有客户列表
     * @return
     */
    @Override
    public List<Client> exportList() {
        return clientDao.exportList();
    }

}
